package com.zxy.day0624_util.utils;

/**
 * @Auther: lenovo
 * @Date: 2021/9/27 20:54
 * @Description:
 */
public class StringUtil {
    private static final String LETTER = "[a-zA-Z]+";
    private static final String PHONE = "^1[3|4|5|6|7|8|9]\\d{9}$";
    private static final String EMAIL = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";

    public StringUtil() {
    }

    public static boolean hasLength(String param) {
        return param != null && param.length() > 0;
    }

    public static boolean hasText(String param) {
        return param != null && param.trim().length() > 0;
    }

    public static String reverse(String param) {
        return !hasText(param) ? param : (new StringBuffer(param)).reverse().toString();
    }

    public static String hiddenStr(String param, int startNum, int endNum) {
        if (!hasText(param)) {
            return "传入数据不正确，数据不能为空";
        } else {
            String head = param.substring(0, startNum);
            String body = param.substring(startNum, endNum);
            String tail = param.substring(endNum);
            String replace = "";

            for(int i = 0; i < body.length(); ++i) {
                replace = replace + "*";
            }

            return head + replace + tail;
        }
    }

    public static boolean isLetter(String param) {
        return !hasText(param) ? false : param.matches("[a-zA-Z]+");
    }

    public static boolean isPhone(String param) {
        return !hasText(param) ? false : param.matches("^1[3|4|5|6|7|8|9]\\d{9}$");
    }

    public static boolean isEmail(String param) {
        return !hasText(param) ? false : param.matches("^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$");
    }
}
